package com.example.sea.core.data.information.service;

import com.example.sea.core.common.utils.UUIDUtil;
import com.example.sea.core.data.information.entity.InformationNotice;
import com.example.sea.core.data.information.mapper.InformationNoticeMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class InformationNoticeService {

    @Autowired
    private InformationNoticeMapper informationNoticeMapper;

    public PageInfo<InformationNotice> findPageByParams(Map params) {
        PageHelper.startPage(Integer.valueOf(params.get("pageNum").toString()), Integer.valueOf(params.get("pageSize").toString()));
        List<InformationNotice> informationNoticeList = informationNoticeMapper.selectListByParamsMap(params);
        PageInfo<InformationNotice> pageInfo = new PageInfo<>(informationNoticeList);
        return pageInfo;
    }

    public int add(InformationNotice informationNotice){
        informationNotice.setId(UUIDUtil.getUUID32());
        informationNotice.setCreateTime(new Date());
        return informationNoticeMapper.insert(informationNotice);
    }
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Transactional
    public int delete(String[] ids){
        int count=0;
        for (String id:ids) {
            count+=informationNoticeMapper.deleteByPrimaryKey(id);
        }
        return count;
    }

    /**
     * 根据ID进行查询
     * @param id
     * @return
     */
    public InformationNotice findById(String id){
        return informationNoticeMapper.selectByPrimaryKey(id);
    }


}
